using System.Configuration;
using System;
using System.Net;
using NMollom;

public partial class _Default : System.Web.UI.Page 
{
    protected void Submitter_Click(object sender, EventArgs e) {
        Mollom mollom = new Mollom(ConfigurationManager.AppSettings["MollomPublicKey"],
                                   ConfigurationManager.AppSettings["MollomPrivateKey"]);

        ContentAssesment lastCheck = ViewState["LastCheck"] as ContentAssesment;

        // first call
        ImageCaptcha captcha = ViewState["Captcha"] as ImageCaptcha;
        if (captcha == null) {
            ContentAssesment check = mollom.CheckContent("", TestBody.Text, "", "", "", "", "", IPAddress.Parse(Request.UserHostAddress), lastCheck);
            Ham.Visible = check.IsHam() || check.IsUnsure();
            Spam.Visible = check.IsSpam() || check.IsUnsure();
            Results.Text = check.IsUnsure() ? check.Quality.ToString("0.00") : "";

            if (check.IsHam()) 
                Response.Redirect("http://www.mollom.com");
            else if (check.IsUnsure()) {
                captcha = check.GetImageCaptcha();
                ViewState["Captcha"] = captcha;
                CaptchaImage.ImageUrl = captcha.Url;
                CaptchaPanel.Visible = true;
            }
        }
        else {
            if (captcha.Check(mollom, CaptchaSolution.Text)) {
                Response.Redirect("http://www.mollom.com");
            }
        }
    }
}
